package com.cskaoyan.shopping.controller;


import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.dto.*;
import com.cskaoyan.shopping.service.Categories;
import com.cskaoyan.shopping.service.IContentService;
import com.cskaoyan.shopping.service.IHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

@RestController
public class HomePageController {
    @Autowired
    IHomeService iHomeService;

    @GetMapping("/shopping/homepage")
    public ResponseData getProductDetail() {
        HomePageResponse homepage = iHomeService.homepage();

        if (ShoppingRetCode.SUCCESS.getCode().equals(homepage.getCode())) {
            // 业务方法调用成功
            Set<PanelDto> panelContentItemDtos = homepage.getPanelContentItemDtos();
            return new ResponseUtil().setData(panelContentItemDtos);
        }
        return new ResponseUtil().setErrorMsg(homepage.getMsg());
    }


   @Autowired
    IContentService iContentService;
    @GetMapping("/shopping/navigation")
    public ResponseData navigation() {
        NavListResponse navListResponse = iContentService.queryNavList();

        if (ShoppingRetCode.SUCCESS.getCode().equals(navListResponse.getCode())) {
            // 业务方法调用成功
            List<PanelContentDto> pannelContentDtos = navListResponse.getPannelContentDtos();
            return new ResponseUtil().setData(pannelContentDtos);
        }
        return new ResponseUtil().setErrorMsg(navListResponse.getMsg());
    }



@Autowired
Categories categories;
    @GetMapping("/shopping/categories")
    public ResponseData categories() {
        CategoriesResponse categoriesResponse = categories.getCategoriesList();

        if (ShoppingRetCode.SUCCESS.getCode().equals(categoriesResponse.getCode())) {
            // 业务方法调用成功
            List<com.cskaoyan.shopping.dal.entitys.Categories> categoriesResponse1 = categoriesResponse.getCategoriesResponse();
            return new ResponseUtil().setData(categoriesResponse1);
        }
        return new ResponseUtil().setErrorMsg(categoriesResponse.getMsg());
    }

}
